package com.mornd.gulimall.order.entity.vo;

import com.mornd.gulimall.apis.cart.to.CartItemTo;
import com.mornd.gulimall.apis.member.to.MemberReceiveAddressTo;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

/**
 * @author: mornd
 * @dateTime: 2023/8/21 - 22:13
 */

@Data
public class OrderConfirmVO {

    // 收货地址
    private List<MemberReceiveAddressTo> address = Collections.emptyList();

    // 商品项
    private List<CartItemTo> items = Collections.emptyList();

    // 会员积分
    private Integer integeration;

    private String orderToken;

    // 订单总金额
//    private BigDecimal total;

    // 应付价钱
//    private BigDecimal payPrice;

    private int count;

    public BigDecimal getTotal() {
        return items.stream()
                // 价格 * 数量
                .map(i -> i.getPrice().multiply(new BigDecimal(i.getCount().toString())))
                // 相加
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    public int getCount() {
        return this.items.stream().map(CartItemTo::getCount).reduce(0, Integer::sum);
    }

    public void setCount(int count) {
        this.count = count;
    }
}
